package 富婆梦.第一阶段.Java基础视频学习.线程的练习.练习;

/**
 * @ProjectName: java-learning
 * @Package: 富婆梦.第一阶段.线程的练习.练习
 * @ClassName: LiftOff
 * @Author: hemengjin
 * @Description: 继承Runable接口，显示发射之前的倒计时
 * @Date:2021/10/18 17:22
 * @Version: 1.0
 */
public class LiftOff implements Runnable {
    protected int countDown = 10;
    private static int taskCount = 0;
    private final int id = taskCount++;

    public LiftOff() {
    }

    public LiftOff(int countDown) {
        this.countDown = countDown;
    }

    public String status() {
        return "#" + id + "(" + (countDown > 0 ? countDown : "Lifttoff") + ");";
    }

    @Override
    public void run() {
        while (countDown-->0){
            System.out.print(status());
            Thread.yield();//线程让步：当线程执行到这里会把自己的执行时间让出来，让自己或其他线程运行
        }

    }


}
